import java.util.Arrays;
import java.util.Comparator;
import java.util.Objects;
import java.util.PriorityQueue;


class Student {
    String name;

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Student student = (Student) o;
        return Objects.equals(name, student.name);
    }

    @Override
    public int hashCode() {
        return Objects.hash(name);
    }
}
class IntBig implements Comparator<Integer> {

    @Override
    public int compare(Integer o1, Integer o2) {
        return o1.compareTo(o2);
    }
}
public class Test {

    public static void main(String[] args) {

        PriorityQueue<Integer> minHeap = new PriorityQueue<>(new IntBig());

        minHeap.offer(1);

        minHeap.offer(2);

        System.out.println(minHeap.peek());


    }

    //o(n*logK)
    public static int[] findKmax(int[] array,int k) {
        PriorityQueue<Integer> minHeap = new PriorityQueue<>();
        //O(K * logK)
        for (int i = 0; i < k; i++) {
            minHeap.offer(array[i]);
        }

        //(n-k) * logK
        for (int i = k; i < array.length; i++) {
            int top = minHeap.peek();
            if(top < array[i]) {
                minHeap.poll();
                minHeap.offer(array[i]);
            }
        }

        int[] ret = new int[k];
        for (int i = 0; i < k; i++) {
            ret[i] = minHeap.poll();
        }
        return ret;
    }

    public static void main4(String[] args) {
        int[] array = {1,13,41,51,61,71,19};
        int[] ret = findKmax(array,3);
        System.out.println(Arrays.toString(ret));
    }

    public int[] find(int[] array,int k) {
        PriorityQueue<Integer> minHeap = new PriorityQueue<>();
        //O(n*logN)
        for (int i = 0; i < array.length; i++) {
            minHeap.offer(array[i]);
        }
        //k*logN
        int[] ret = new int[k];
        for (int i = 0; i < k; i++) {
            ret[i] = minHeap.poll();
        }
        return ret;
    }

    public static void main3(String[] args) {
        PriorityQueue<Student> priorityQueue = new PriorityQueue<>();
        priorityQueue.offer(null);
    }

    public static void main2(String[] args) {
        //默认是一个小根堆
        PriorityQueue<Integer> priorityQueue = new PriorityQueue<>();
        priorityQueue.offer(1);
        priorityQueue.offer(3);
        priorityQueue.offer(4);
        priorityQueue.offer(7);

        System.out.println(priorityQueue.peek());

    }
    public static void main1(String[] args) {
        TestHeap testHeap = new TestHeap();
        int[] array = {27,15,19,18,28,34,65,49,25,37};
        testHeap.initElem(array);
        //O(N)
        testHeap.createHeap();

        //testHeap.offer(80);
        //testHeap.poll();

        testHeap.heapSort();

    }
}
